<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="frm.ssh.util.page.SearchBean"%>
<%@ include file="/jsp/common/common.jsp"%>
<html>
	<head>
		<script language="javascript" src="<%=contextPath%>/js/func.js" type="text/javascript"></script>
		<script type="text/javascript" src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/ext3/ext-all.js"></script>
		<link rel="stylesheet" type="text/css"	href="<%=contextPath%>/ext3/resources/css/ext-all.css">
		<script>
			Ext.onReady(function(){
				var tb = new Ext.Toolbar({
			   		renderTo: document.all.tbar,
			    	items: [
				        {
				            text: '查询',
				            icon:"<%=contextPath%>/images/query.gif",
				            handler:cmt
				        
				        },'-', 
				         {
				            text: '选择',
				            icon:"<%=contextPath%>/images/pass.gif",
				            handler:setParentMany
				        
				        },'-', 
				        {
				            text: '增加',
				            icon:"<%=contextPath%>/images/add.gif",
				            handler:comt,
				            hidden:<%=session.getAttribute("SESSION_CLASS_LEADER") != null
				            || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true
				            %>
				        
				        },'-', 
				        {
				            text: '删除',
				            icon:"<%=contextPath%>/images/delete.gif",
				            handler:deleteIt,
				            hidden:<%=session.getAttribute("SESSION_CLASS_LEADER") != null
				            || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true
				            %>
				        }
			    	]
			    });
			});
			

		</script>
	</head>
	<body onload="javascript:document.frmM.elements['cydy.dyname'].value = '';">
		<div id ='tbar'></div>
		
		<form id="frmM" class="ct" name="frmM" method="POST" action="<%=contextPath%>/queryUser.do">
			<s:hidden name="cydy.dytypename"/>
			<s:hidden name="cydy.dytype"/>
			<s:hidden name="cydy.sortid"/>
			<s:hidden name="cydy.id"/>
			<s:hidden name="cydy.parentColName"/>
			
			<table width="100%" id="contab">
				<tr>
					<th>
						<c:out value="${cydy.dytypename}"/>
					</th>
					<td>
						<input style="width:99%"type="text" name="cydy.dyname" id="cydy.dyname" value="${cydy.dyname}" maxlength="100"/>
					</td>
				</tr>
			</table>
			<hr>
			<table width="100%" id="listtab">
				<tr>
					<th class="ct" width="25">
						<input name="chkAll" type="checkbox" id="chkAll"
							onclick="javascript:checkAll(this.form, 'id');" value="checkbox">
					</th>
					<td width="25">
							No.
						<br></td>
					<th ><c:out value="${cydy.dytypename}"/></th>
				</tr>

				<c:forEach items="${cydyList}" var="detail" varStatus="status">
					<tr>
						<td width="25">
							<input type="checkbox" name="id" id="id" value="${detail.id}" />
						<br></td>
						<td width="25">
							<script language="javascript">document.write(parseInt('${status.index}') + parseInt(1))</script>
						<br></td>
						<td id="${detail.id}" style="display:none">
							<c:out value="${detail.dyname}"/>
						</td>
						<td >
							<a href="#" onClick="javascript:setParentOne('<c:out value="${detail.dyname}"/>')" />
								<c:out value="${detail.dyname}"/>
							</a>
						</td>
					</tr>
				</c:forEach>

				<c:if test="${cydyList == null || fn:length(cydyList) == 0 }">
					<tr>
						<td colspan="4" style="text-align: center">
							无相关记录
						</td>
					</tr>
				</c:if>
			</table>
		</form>
	</body>
</html>
<script language="javascript">

			// 查询
			function cmt(){
				document.frmM.action = "<%=contextPath%>/dic!initCydy.do";
				document.frmM.submit();
			}

			// 删除
			function deleteIt()
			{
				if(!isChecked("id")) {
		 			alert("请选择要删除的记录");
		 			return false;
		 		}

		    	if(confirm("确定要删除选中的用记录？")) {
		        	document.frmM.action = "<%=contextPath%>/dic!deleteCydy.do";
					document.frmM.submit();
		    	}
			}
			
	 		// 保存
    		 function comt(){
    		 	document.frmM.elements["cydy.id"].value = "0";
     			document.frmM.action = "<%=contextPath%>/dic!saveCydy.do";
     			document.frmM.submit();
     		}
     
			// 单选设置父窗体短语
			function setParentOne(dyname) {
			
				try {
					window.opener.document.frmM.elements["${cydy.parentColName}"].value = dyname;
				} catch(e) {
					alert(e);
				}
				window.close();	
			}
			
			// 多选设置父窗体短语
			function setParentMany() {
			
				try {

					var idArray = getCheckValueMany("id").split(",");

					var v = "";
					for (var i=0; i<idArray.length-1;i++) {
						v += document.getElementById(idArray[i]).innerHTML + ";";					
					}
				
					window.opener.document.frmM.elements["${cydy.parentColName}"].value = v;
					
				} catch(e) {
					alert(e);
				}
				window.close();	
			}
			
		</script>